/*
 * @Descripttion: 获取出库的一些辅助信息
 * @version: 1.0
 * @Author: 自由如风
 * @Date: 2021-05-07 18:11:09
 * @LastEditors: 自由如风
 * @LastEditTime: 2021-05-07 18:25:11
 */
const DB = require('../../lib/DB')
const { Success, Fail } = require('../../lib/Response')
const { DOCTOR } = require('../../lib/Identity')

module.exports = async function (ctx, next) {
    try {
        // 药品类别
        const medicine_lib_list = (await DB.models.medicine_lib.findAll({
            attributes: ['medicine_name', 'id']
        })).map(e => e.toJSON())

        // 医师列表
        const doctor_list = (await DB.models.user.findAll({
            where: {
                identity: DOCTOR
            },
            attributes: ['name', 'id']
        }))
        ctx.body = new Success({
            medicine_lib_list,
            doctor_list
        })
        await next();
    } catch (e) {
        ctx.body = new Fail(e.message)
    }
}